// Package form
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2023 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
package form

// Sorter 排序器，兼容naiveUI
type Sorter struct {
	ColumnKey string      `json:"columnKey"  dc:"排序字段"`
	Order     interface{} `json:"order"      dc:"排序方式 descend|ascend|false"`
}

type Sorters struct {
	Sorters []*Sorter `json:"sorters"  dc:"排序器"`
}

func (s *Sorters) GetSorters() []*Sorter {
	return s.Sorters
}

// 将 map 转换为 Sorters
func (s *Sorters) MapToSorters(inputMap map[string]interface{}) {

	for _, value := range inputMap {
		sorterMap, ok := value.(map[string]interface{})
		if !ok {
			return
		}

		columnKey, _ := sorterMap["columnKey"].(string)
		order, _ := sorterMap["order"].(string)

		sorter := &Sorter{
			ColumnKey: columnKey,
			Order:     order,
		}

		s.Sorters = append(s.Sorters, sorter)
	}

}
